<?php
/**
 * 修改用户信息管理页面
 * author:wang
 * mail:970633164@qq.com
 */
define("PHP_IN", true);
require "../include/init.php";
require "checklogin.php";
require ROOT_PATH."cms/smart_connection.php";

$userid = isset($_GET['userid']) ? $_GET['userid'] : 0;
$page = isset($_GET['page']) ? $_GET['page'] : 1;

$sql = "SELECT * FROM user WHERE userid = $userid";
$result = $db->query($sql);
$user = $db->fetch_one($result);


if (isset($_POST['dosubmit'])) {
    $userid = intval($_POST['userid']);
    $realname = $_POST['realname'];
    $password = $_POST['password'];
    $mobile = $_POST['mobile'];
    $mail = $_POST['mail'];

    $password_md5 = md5($password);

    $sql = "UPDATE user SET password='$password_md5',realname='$realname',mobile='$mobile',email='$mail' WHERE userid = $userid";
    $result = $db->query($sql);
    if ($result) {
        alert("修改成功", "user_list.php?page=".$page);
    } else {
        alert("修改失败");
    }
}

$smarty->assign("user",$user);
$smarty->assign("page",$page);

$smarty->display("user_edit.tpl");
$db->close();
?>
